package eiisan.controller.user;

import eiisan.dao.param.user.Doregister;
import eiisan.service.user.AuthorityService;
import eiisan.service.user.UserService;
import eiisan.util.common.UserUtil;
import eiisan.util.model.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户管理控制器
 *
 * @author gragonfly
 * @date 2019/7/6
 **/
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理控制器")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private AuthorityService authorityService;

    @GetMapping("/info/self")
    @ApiOperation(value = "查看本用户信息接口")
    public Result getUserInfo() {
        //UserUtil.get()
        return Result.success();
    }

    @GetMapping("/info/byId")
    @ApiOperation(value = "查看用户信息接口")
    public Result getUserInfoById(@RequestParam("userId") @ApiParam(value = "用户ID", required = true) Long userId) {
        return authorityService.getUserDetail(userId);
    }

    @GetMapping("/info/byName")
    @ApiOperation(value = "查看用户信息接口")
    public Result getUserInfoByName(@RequestParam("userName") @ApiParam(value = "用户名",
            required = true) String userName) {
        return authorityService.getUserDetailByUsername(userName);
    }

    @GetMapping("/infos/byName")
    @ApiOperation(value = "批量查看用户信息接口")
    public Result getUserInfosByName(@RequestParam("userName") @ApiParam(value = "用户名列表", required = true) List<String> userNames) {
        return authorityService.getUserDetailByNames(userNames, false);
    }

    @PostMapping("/register")
    @ApiOperation(value = "注册接口")
    public Result register(@RequestBody @ApiParam(value = "用户注册请求参数", required = true) Doregister param) {
        return userService.register(param);
    }


}
